var AddUser = {};
AddUser.contextpath = "";
AddUser.initPage = function(contextpath) {
	AddUser.contextpath = contextpath;

	layui.use(['form', 'layedit', 'laydate'], function(){
		  var form = layui.form
		  ,layer = layui.layer
		 
		  //自定义验证规则
		  form.verify({
			  userName: function(value){
		      layedit.sync(editIndex);
		    }
		  });
		  
		  //监听提交
		  form.on('submit(submit)', function(data){
			  AddUser.ajaxSaveUser(data);
		    return false;
		  });
		//监听指定开关
		  form.on('switch(switchTest)', function(data){
			  if(this.checked){
				  layer.tips('可以记录用户额外信息', data.othis);
				  $("#extra").css("display","");
			  }else{
				  $("#extra").css("display","none");
			  }
		   
		  });
		});
}


AddUser.ajaxSaveUser = function(data1) {
	$.ajax({
		type : "POST",
		url : "/web2019/user/ajaxSaveUser.action",
		dataType : "json",
		data : data1.field,
		beforeSend:function(){
			layer.load(1);
		},
		complete:function(){
			layer.close(layer.index-1);
		},
		success : function(data) {
			if (data.code == "0000") {
				layer.alert(data.message, { icon: 1, closeBtn: 0 }, function (index) { 
					layer.close(index);
					window.location.href="/web2019/user/addUser.action";
				});
			} else {
				layer.alert(data.message);
			}
		},
		error : function(data) {

		}
	});
}
